<template>
	<view>
		<view class="cn">
			<view class="info">
				<view class="form_group hr">
					<view class="lable">标题名称</view>
					<input type="text" placeholder="请输入标题名称" v-model="item.title" />
				</view>
				<view class="form_group"><view class="lable">投诉内容</view></view>
				<textarea placeholder="请输入投诉内容(500字以内)" v-model="item.content" maxlength="500" style="height: 150px;" />
				<view class="form_group">
					<view class="lable">投诉图片</view>
					<view class="text">最多上传5张图片</view>
				</view>
				<view class="pl5">
					<u-upload
						:ip="ip"
						:action="upload.action"
						:header="upload.header"
						:size-type="upload.size"
						:max-count="upload.count"
						:name="upload.name"
						:file-list="item.pic"
						:deletable="item.auditFlag != 1"
						:show-progress="item.auditFlag != 1"
						:custom-btn="item.auditFlag == 1"
						ref="uUpload"
						width="140"
						height="140"
					></u-upload>
				</view>
				<view class="form_group">
					<view class="lable">手机号码</view>
					<input type="text" placeholder="(选填),以便将处理结果反馈给你" v-model="item.phone" style="flex: 0.8;" />
				</view>
			</view>
			<button class="btn" @click="up()">提交投诉</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.$http.urls.ip,
			item: { pic: [] },
			upload: {
				header: { apiToken: this.$getUser().apiToken },
				name: 'img',
				action: this.$http.urls.uploadImg,
				size_type: 'compressed ',
				count: 5
			}
		};
	},
	onLoad(e) {},
	methods: {
		up() {
			this.item.pic = [];
			let files = this.$refs.uUpload.lists.filter(val => {
				return val.progress == 100;
			});
			//投诉图片
			files.forEach(item => {
				if (item.response) {
					this.item.pic.push(item.response.fileName); //获取上传成功的网络地址
				} else {
					this.item.pic.push(item.url); //原来的地址
				}
			});
			let rule = [{ name: 'title', checkType: 'notnull', errorMsg: '请输入标题名称' }, { name: 'content', checkType: 'notnull', errorMsg: '请输入投诉内容' }];
			if (!this.$verify.check(this.item, rule)) {
				uni.showModal({ content: this.$verify.error, showCancel: false });
				return;
			}
			this.item.pic = this.item.pic.toString();
			this.$http.request({
				method: 'POST',
				url: this.$http.urls.feedback,
				data: this.item,
				success: res => {
					uni.showToast({ title: '提交成功' });
					setTimeout(() => {
						uni.navigateBack();
					}, 700);
				}
			});
		}
	}
};
</script>

<style lang="scss">
.steps {
	text-align: center;
	margin-top: 20px;
}
.u-subsection {
	margin-top: 20px;
}
.cn {
	padding: 15px;
	.info {
		background-color: white;
		border-radius: 5px;
		margin-top: 10px;
		padding-bottom: 10px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		.dw {
			top: 11px;
			font-size: 19px;
			right: 9px;
			position: absolute;
		}
	}
	textarea {
		margin-left: 17px;
		font-size: 14px;
		padding: 10px;
		width: 85%;
		height: 85px;
		border: 1px solid #f1f1f1;
		border-radius: 5px;
	}
	.btn {
		margin-top: 25px;
	}
}
.text {
	font-size: 11px;
	font-weight: normal;
	color: $dar;
	flex: 0.8;
	text-align: right;
}
</style>
